package com.myhome.money.base.datastructure;

/**
 * 递归
 *
 * @Author: 许路路
 * @Date: 2019/4/26
 */
public class Recursive {
    //编程实现斐波那契数列求值 f(n) = f(n-1) + f(n-2)
    //编程实现求阶乘 n!
    //编程实现一个数据集合的全排列


    public static void main(String[] args) {
        int res = fibonacci(4);
        System.out.println("......" + res);
        System.out.println("下面开始求阶乘......");
        res = factorial(12);
        System.out.println("......" + res);

    }

    /**
     * 斐波那契数列
     *
     * @param n
     * @return
     */
    public static int fibonacci(int n) {
        if (n <= 0) {
            return 0;
        }
        if (n == 2 || n == 1) {
            return 1;
        }
        return fibonacci(n - 1) + fibonacci(n - 2);
    }

    public static int factorial(int n) {
        if (n <= 1) {
            return 1;
        }
        return factorial(n - 1) * n;
    }

    public static void fullyArranged(int[] arr) {
        
    }

}
